package com.example.coupon.controller;

import com.alibaba.fastjson.JSON;
import com.example.coupon.exception.CouponException;
import com.example.coupon.executor.ExecutorManager;
import com.example.coupon.vo.SettlementInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 结算服务的Controller
 * @author wangbo
 * @description:
 * @date 2021/2/2014:04
 */
@Slf4j
@RestController
public class SettlementController {

    private final ExecutorManager executorManager;

    public SettlementController(ExecutorManager executorManager) {
        this.executorManager = executorManager;
    }

    /**
     * 优惠券结算
     * @param settlement
     * @return
     * @throws CouponException
     */
    @PostMapping("/settlement/compute")
    public SettlementInfo computeRule(@RequestBody SettlementInfo settlement)throws CouponException{
        log.info("settlement:{}", JSON.toJSONString(settlement));
        return executorManager.computeRule(settlement);
    }
}
